/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package toesp.bean;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import toesp.entity.Groupuser;

/**
 *
 * @author satria.sp
 */
public class GroupuserBean {
    private EntityManagerFactory emf;

    public GroupuserBean() {
        emf = Persistence.createEntityManagerFactory("swing-researchPU");
    }

    private EntityManager getEntityManager() {
        return emf.createEntityManager();
    }
    
    private void getCloseEntityManager() {
        emf.close();
    }
    
    public Groupuser getByPengguna(String p_strPgUid) throws Exception {  
        Groupuser ObjGu = new Groupuser();
        
        try {
            EntityManager em = getEntityManager();
            Query q = em.createQuery("SELECT o FROM Groupuser o WHERE o.penggUid=:p_strPgUid");     
            q.setParameter("p_strPgUid", p_strPgUid);
            List<Groupuser> lstGroup = q.getResultList();
            ObjGu = lstGroup.get(0);
        } catch (Exception e) { 
            System.out.println("Salahmu : "+e.getMessage());
        }finally{
            //this.getCloseEntityManager();
        }  
        
        return ObjGu;
    }  
    
    public void commitaj(){
        
    }
}
